package com.qf.blog.controller;

import com.qf.blog.commons.utils.ConvertUtils;
import com.qf.blog.dto.UserDTO;
import com.qf.blog.entity.User;
import com.qf.blog.service.ISysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping ("/sys/user")
@Slf4j
public class SysUserController {
    @Autowired
    private ISysUserService userService;

    @GetMapping
    public List<UserDTO> list() {
        return userService.queryAll();
    }

    @GetMapping ("/{id}")
    public UserDTO queryOne(@PathVariable String id) {
        User user = userService.getById(id);
        UserDTO userDTO = ConvertUtils.sourceToTarget(user, UserDTO.class);
        return userDTO;
    }

    @PostMapping
    public Boolean add(@RequestBody UserDTO user) {
        return userService.add(user);
    }

    @PostMapping ("/update")
    public Boolean update(@RequestBody UserDTO user) {
        return userService.updateById(user);
    }

    @PostMapping ("/delete")
    public boolean removeBatch(@RequestBody List<String> ids) {
        return userService.removeByIds(ids);
    }

}
